package com.itheima.aspect;

import org.aspectj.lang.ProceedingJoinPoint;

public class PermissionAspect {
    public void checkPermission() {
        System.out.println("权限校验！");
    }

    public void printLog(){
        System.out.println("打印日志...");
    }

    public void showException(){
        System.out.println("出现异常了，请检查...");
    }

    public void showEnd(){
        System.out.println("执行完毕...");
    }

    //计算目标方法的执行时长
    public void showMillions(ProceedingJoinPoint joinPoint){
        //1. 记录当前时间
        long timeMillis1 = System.currentTimeMillis();
        //2. 执行目标方法
        try {
            joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        //3. 再记录当前时间
        long timeMillis2 = System.currentTimeMillis();
        //4. 将两次的时间相减，得到方法的执行时长
        System.out.println(timeMillis2 - timeMillis1);
    }
}
